﻿Imports System.Net
Imports System.Web.Http
Imports Models.Users

Namespace Controllers

    Public Class CompanyController
        Inherits ApiController

        ''' <summary>
        ''' Get Company By Id
        ''' </summary>
        ''' <param name="id"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function [Get](id As Integer) As CompanyVO
            Try
                Dim oService As New Services.Companies(Request)
                Dim oEntity As CompanyVO = oService.Get(id)
                Return oEntity
            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function


        ''' <summary>
        ''' Get List of Companies
        ''' </summary>
        ''' <param name="companyId">Optional for filter</param>
        ''' <returns>Array of Companies</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function List(Optional companyId As Integer = -1) As Generic.List(Of Models.Users.CompanyVO)
            Try
                Dim oService As New Services.Companies(Request)
                Return oService.List(companyId)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return Nothing
            End Try
        End Function

        ''' <summary>
        ''' Get List of Companies
        ''' </summary>
        ''' <param name="companyId">Optional for filter</param>
        ''' <returns>Array of Companies</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function ListFull(Optional companyId As Integer = -1) As Generic.List(Of Models.Users.FullCompanyVO)
            Try
                Dim oService As New Services.Companies(Request)
                Return oService.ListFull(companyId)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return Nothing
            End Try
        End Function

        ''' <summary>
        ''' Update Company
        ''' </summary>
        ''' <param name="company">Company object</param>
        ''' <returns>Boolean</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("PUT")> _
        Public Function Update(company As companyvo) As Integer
            Try
                Dim oService As New Services.Companies(Request)
                Return oService.Update(company)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

        ''' <summary>
        ''' Create a Company
        ''' </summary>
        ''' <param name="company"></param>
        ''' <returns>The new ID  of the entity</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("POST")> _
        Public Function Create(company As CompanyVO) As Integer
            Try
                Dim oService As New Services.Companies(Request)
                Return oService.Create(company)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

        ''' <summary>
        ''' Delete a company
        ''' </summary>
        ''' <param name="id">companyId</param>
        ''' <returns>1 if OK</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("DELETE")>
        Public Function Delete(id As Integer) As Integer
            Try
                Dim oService As New Services.Companies(Request)
                Return oService.Delete(id)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function


    End Class

End Namespace